﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace BLL
{
    public class CongNhanBLL
    {

        public List<CongNhan> GetAllCongNhan()
        {
            using (var cc = new ChamCongEntities())
            {               
                return cc.CongNhans.Include("TinhThanh").Include("TinhThanh1").ToList<CongNhan>();
            }
        }
        public CongNhan GetCongNhanById(int id)
        {
            using (var cc = new ChamCongEntities())
            {
                return (CongNhan)cc.CongNhans.Where(cn => cn.CongNhanId == id).FirstOrDefault();
            }
            
        }
        public void InsertCongNhan(CongNhan congnhan)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(congnhan).State = EntityState.Added;
                cc.SaveChanges();
            }
        }
        public void UpdateCongNhan(CongNhan congnhan)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(congnhan).State = EntityState.Modified;
                cc.SaveChanges();
            }
        }
        public void DeleteCongNhan(CongNhan congnhan)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(congnhan).State = EntityState.Deleted;
                cc.SaveChanges();
            }
        }
    }
}
